package net.zui.comp;

import java.awt.Color;
import java.awt.Graphics2D;
import net.zui.Option;
import net.zui.entity.ZBorder;
import net.zui.inter.IGroup;
/**
 * 方块组件,用于在窗体上绘制各种颜色/边框的方块,一般用于区域分隔
 * <br /><br />
 * <b>作者:</b>张天文 <br />
 * <b>日期:</b>2021年4月21日上午10:07:56<br />
 * @date
 */
public class ZRect extends ZBase {
	protected Color backColor=Option.getBackColor();
	protected ZBorder border=null;
	
	public ZRect(IGroup frame, int width, int height,Color backColor) {
		super(frame, width, height);
		this.backColor=backColor;
	}
	
	public ZRect(IGroup frame, int x, int y, int width, int height,Color backColor) {
		super(null, frame, x, y, width, height);
		this.backColor=backColor;
	}
	
	public ZRect(String id, IGroup frame, int x, int y, int width, int height,Color backColor) {
		super(id, frame, x, y, width, height);
		this.backColor=backColor;
	}
	
	public ZRect(IGroup frame, int x, int y, int width, int height, int index,Color backColor) {
		super(null, frame, x, y, width, height, index);
		this.backColor=backColor;
	}

	public ZRect(String id, IGroup frame, int x, int y, int width, int height, int index,Color backColor) {
		super(id, frame, x, y, width, height, index);
		this.backColor=backColor;
	}

	@Override
	protected void draw(Graphics2D g) {
		boolean isOne=border==null || border.getLine()==0;		
		if(isOne) {		
			g.setColor(backColor);
			g.fillRect(0, 0, outerWidth-1, outerHeight-1);
			return;
		}
		int radius=border.getRadius();
		int line=border.getLine();
		g.setColor(border.getBorderColor());
		if(radius==0) {
			g.fillRect(0, 0, outerWidth-1, outerHeight-1);
		}else {
			g.fillRoundRect(0, 0, outerWidth-1, outerHeight-1,radius,radius);
		}
		g.setColor(backColor);
		if(radius==0) {
			g.fillRect(line, line, outerWidth-line-1, outerHeight-line-1);
		}else {
			g.fillRoundRect(line, line, outerWidth-line-line-1, outerHeight-line-line-1,radius,radius);
		}

		/*
		try {
			ImageIO.write(img, "png", new File("C:\\Users\\Administrator\\Desktop\\ccc.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		*/
	}

	public Color getBackColor() {
		return backColor;
	}

	public void setBackColor(Color backColor) {
		this.backColor = backColor;
	}

	public ZBorder getBorder() {
		return border;
	}

	public void setBorder(ZBorder border) {
		this.border = border;
	}
}
